package com.bh.web.controller.wms;

import com.bh.common.annotation.Log;
import com.bh.common.core.controller.BaseController;
import com.bh.common.core.domain.AjaxResult;
import com.bh.common.core.page.TableDataInfo;
import com.bh.common.enums.BusinessType;
import com.bh.common.utils.poi.ExcelUtil;
import com.bh.wms.domain.WmsInboundOrder;
import com.bh.wms.service.IWmsInboundOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 入库单管理接口
 *
 * @author GPT
 */
@Api(tags = "入库管理")
@RestController
@RequestMapping("/wms/inbound")
public class WmsInboundOrderController extends BaseController {

    @Autowired
    private IWmsInboundOrderService inboundOrderService;

    @ApiOperation("分页查询入库单")
    @PreAuthorize("@ss.hasPermi('wms:inbound:list')")
    @GetMapping("/list")
    public TableDataInfo list(WmsInboundOrder query) {
        startPage();
        List<WmsInboundOrder> list = inboundOrderService.selectWmsInboundOrderList(query);
        return getDataTable(list);
    }

    @ApiOperation("导出入库单")
    @PreAuthorize("@ss.hasPermi('wms:inbound:export')")
    @Log(title = "入库单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WmsInboundOrder query) {
        List<WmsInboundOrder> list = inboundOrderService.selectWmsInboundOrderList(query);
        ExcelUtil<WmsInboundOrder> util = new ExcelUtil<>(WmsInboundOrder.class);
        util.exportExcel(response, list, "入库单数据");
    }

    @ApiOperation("获取入库单详情")
    @PreAuthorize("@ss.hasPermi('wms:inbound:query')")
    @GetMapping("/{id}")
    public AjaxResult getInfo(@PathVariable Long id) {
        return success(inboundOrderService.selectWmsInboundOrderById(id));
    }

    @ApiOperation("新增入库单")
    @PreAuthorize("@ss.hasPermi('wms:inbound:add')")
    @Log(title = "入库单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WmsInboundOrder entity) {
        return toAjax(inboundOrderService.insertWmsInboundOrder(entity));
    }

    @ApiOperation("修改入库单")
    @PreAuthorize("@ss.hasPermi('wms:inbound:edit')")
    @Log(title = "入库单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WmsInboundOrder entity) {
        return toAjax(inboundOrderService.updateWmsInboundOrder(entity));
    }

    @ApiOperation("更新入库单状态")
    @PreAuthorize("@ss.hasPermi('wms:inbound:edit')")
    @Log(title = "入库单", businessType = BusinessType.UPDATE)
    @PutMapping("/status")
    public AjaxResult changeStatus(@RequestBody WmsInboundOrder entity) {
        return toAjax(inboundOrderService.changeStatus(entity));
    }

    @ApiOperation("删除入库单")
    @PreAuthorize("@ss.hasPermi('wms:inbound:remove')")
    @Log(title = "入库单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(inboundOrderService.deleteWmsInboundOrderByIds(ids));
    }
}

